# ------------------------------------------
# 准备工作
# ------------------------------------------

setwd("/Users/eimei/Documents/Rdata/")  # 设定工作空间
data <- read.csv("HRdata.csv")  # 读取数据

newdata <- data[c("EmployeeNumber", "Age", "Department",
                  "EnvironmentSatisfaction", "JobSatisfaction",
                  "MonthlyIncome", "RelationshipSatisfaction")]

head(newdata)

# ------------------------------------------
# 任务一
# ------------------------------------------
newdata <- newdata[order(newdata$Age), ]
head(newdata)
newdata <- newdata[order(-newdata$Age), ]
head(newdata)

# ------------------------------------------
# 任务二
# ------------------------------------------
newdata <- newdata[order(newdata$Department), ]
head(newdata)

newdata <- newdata[order(-newdata$Department), ]

newdata <- newdata[order(newdata$Department, decreasing =TRUE),]
head(newdata)

# ------------------------------------------
# 任务三
# ------------------------------------------
attach(newdata)
newdata <- newdata[order(EnvironmentSatisfaction, JobSatisfaction, -RelationshipSatisfaction), ]
head(newdata)
detach(newdata)